# -*- coding: UTF-8 -*-
# @Time : 2021-03-01 9:40
# @File : MiniProgram.py
import time
from data.ExcelConfig import TestSteps
from utils.LogUtil import my_log

log = my_log('MiniProgram')


def Start_MiniProgram(driver):
    try:
        size = driver.get_window_size()
        driver.swipe(size['width'] * 0.5, size['height'] * 0.3, size['width'] * 0.5, size['height'] * 0.8, 200)
        time.sleep(2)
        driver.find_element_by_android_uiautomator('text("测试优校通")').click()
        time.sleep(10)
        cons = driver.contexts
        log.info(cons)
        time.sleep(2)
        driver.switch_to.context('WEBVIEW_com.tencent.mm:appbrand0')
        log.info('切换{}成功'.format(cons))
    except Exception as e:
        log.error(e)


def window_handles(driver):
    try:
        time.sleep(5)
        handles = driver.window_handles
        log.info('当前所有handles：{}'.format(handles))
        # 遍历handles
        for i in handles:
            driver.switch_to.window(i)
            if str(TestSteps.STEP_NAME) in driver.page_source:
                break
        log.info('切换{}成功'.format(handles))
        time.sleep(2)
    except Exception as e:
        log.error(e)
